/*
 * Copyright (C) 2017 The MoonLake Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


package com.minecraft.moonlake.legendaryweaponrel.weapons.bow;

import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class Rain extends WeaponAbstractBowBase {

    public Rain() {
        super("rain", "&b虹吸雨", Material.BOW);
    }

    @Override
    public String[] getLore() {
        return new String[] {
                "&7被此弓射中的玩家将会获得&a饥饿1 5s &7效果"
        };
    }

    @Override
    protected void onBowShoot(EntityShootBowEvent event, Player player, Arrow arrow) {
        // 处理弓射箭
        arrow.setMetadata(type, new FixedMetadataValue(getInstance(), (byte) 1));
    }

    @Override
    protected void onDamage(EntityDamageByEntityEvent event, Arrow arrow, Entity source) {
        // 处理弓箭伤害
        if(!arrow.hasMetadata(type)) return; // 没有属性值则说明非
        if(!(source instanceof Player)) return; // 受伤者不为玩家则返回

        ((Player) source).addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 5 * 20, 1));
    }
}
